import dva from 'dva';
import './index.css';
import 'core-js';
import createLoading from 'dva-loading';
import models from './models/index';
import { message } from 'antd';
import createHistory from 'history/createHashHistory';
//import createHistory from 'history/createBrowserHistory';
Object.assign(window, { Promise: require('pinkie-promise') });
// 1. Initialize
const app = dva({
    history: createHistory(),
    onError(e, dispatch) {
        switch (e.message) {
            case 'clear':
                dispatch({ type: 'user/clear' });
                break;
            default:
                message.error(e.message);
                break;
        }
        e['callback'] && e['callback'](false);
    },
});

// 2. Plugins
app.use(createLoading());

// 3. Model
//app.model(require('./models/example').default);
models.forEach((f) => {
    app.model(f);
});

// 4. Router
app.router(require('./router'));

// 5. Start
app.start('#root');
